package com.frxuexi.sign

import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.base.entity.SignBeanItem
import com.frxuexi.sign.databinding.ItemSignBinding

class SignAdapter:BaseQuickAdapter<SignBeanItem,BaseViewHolder>(R.layout.item_sign) {
    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemSignBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: SignBeanItem) {
        val binding = DataBindingUtil.getBinding<ItemSignBinding>(helper.itemView)!!
        binding.bean=item

        val moring = if(item.morningCheckIn.isNotEmpty()) item.morningCheckIn.split(" ") else emptyList()
        binding.signDate.setText(moring[0].replaceFirst("-","年").replaceFirst("-","月").plus("日"))

        binding.signTime.setText("上班${moring[1]}")
        if(item.afternoonCheckIn.isNotEmpty()){
            binding.signTime.append("-下班${item.afternoonCheckIn.split(" ")[1]}")
        }
    }
}